home *** CD-ROM | disk | FTP | other *** search
/ Digitalfoto 118 / Digitalfoto 118.iso / mac / programas / 00 / start.swf / scripts / __Packages / mx / video / NCManager.as < prev    next >
Text File  |  2009-11-16  |  27KB  |  859 lines

  1. class mx.video.NCManager implements mx.video.INCManager
  2. {
  3.    static var version = "1.0.1.10";
  4.    static var shortVersion = "1.0.1";
  5.    var DEFAULT_TIMEOUT = 60000;
  6.    static var RTMP_CONN = [{protocol:"rtmp:/",port:"1935"},{protocol:"rtmp:/",port:"443"},{protocol:"rtmpt:/",port:"80"},{protocol:"rtmps:/",port:"443"}];
  7.    function NCManager()
  8.    {
  9.       this.initNCInfo();
  10.       this.initOtherInfo();
  11.       this._timeoutIntervalId = 0;
  12.       this._tryNCIntervalId = 0;
  13.       this._timeout = this.DEFAULT_TIMEOUT;
  14.       this._nc = undefined;
  15.       this._ncConnected = false;
  16.    }
  17.    function initNCInfo()
  18.    {
  19.       this._isRTMP = undefined;
  20.       this._serverName = undefined;
  21.       this._wrappedURL = undefined;
  22.       this._portNumber = undefined;
  23.       this._appName = undefined;
  24.    }
  25.    function initOtherInfo()
  26.    {
  27.       this._contentPath = undefined;
  28.       this._streamName = undefined;
  29.       this._streamLength = undefined;
  30.       this._streamWidth = undefined;
  31.       this._streamHeight = undefined;
  32.       this._streams = undefined;
  33.       this._autoSenseBW = false;
  34.       this.fpadZone = undefined;
  35.       this._payload = 0;
  36.       this._connTypeCounter = 0;
  37.       this.cleanConns();
  38.    }
  39.    function getTimeout()
  40.    {
  41.       return this._timeout;
  42.    }
  43.    function setTimeout(t)
  44.    {
  45.       this._timeout = t;
  46.       if(this._timeoutIntervalId != 0)
  47.       {
  48.          clearInterval(this._timeoutIntervalId);
  49.          this._timeoutIntervalId = setInterval(this,"_onFCSConnectTimeOut",this._timeout);
  50.       }
  51.    }
  52.    function getBitrate()
  53.    {
  54.       return this._bitrate;
  55.    }
  56.    function setBitrate(b)
  57.    {
  58.       if(this._isRTMP == undefined || !this._isRTMP)
  59.       {
  60.          this._bitrate = b;
  61.       }
  62.    }
  63.    function getVideoPlayer()
  64.    {
  65.       return this._owner;
  66.    }
  67.    function setVideoPlayer(v)
  68.    {
  69.       this._owner = v;
  70.    }
  71.    function getNetConnection()
  72.    {
  73.       return this._nc;
  74.    }
  75.    function getStreamName()
  76.    {
  77.       return this._streamName;
  78.    }
  79.    function isRTMP()
  80.    {
  81.       return this._isRTMP;
  82.    }
  83.    function getStreamLength()
  84.    {
  85.       return this._streamLength;
  86.    }
  87.    function getStreamWidth()
  88.    {
  89.       return this._streamWidth;
  90.    }
  91.    function getStreamHeight()
  92.    {
  93.       return this._streamHeight;
  94.    }
  95.    function connectToURL(url)
  96.    {
  97.       this.initOtherInfo();
  98.       this._contentPath = url;
  99.       if(this._contentPath == null || this._contentPath == undefined || this._contentPath == "")
  100.       {
  101.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH);
  102.       }
  103.       else
  104.       {
  105.          var _loc2_ = this.parseURL(this._contentPath);
  106.          if(_loc2_.streamName == undefined || _loc2_.streamName == "")
  107.          {
  108.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  109.          }
  110.          else if(_loc2_.isRTMP)
  111.          {
  112.             var _loc3_ = this.canReuseOldConnection(_loc2_);
  113.             this._isRTMP = true;
  114.             this._protocol = _loc2_.protocol;
  115.             this._streamName = _loc2_.streamName;
  116.             this._serverName = _loc2_.serverName;
  117.             this._wrappedURL = _loc2_.wrappedURL;
  118.             this._portNumber = _loc2_.portNumber;
  119.             this._appName = _loc2_.appName;
  120.             if(!(this._appName == undefined || this._appName == "" || this._streamName == undefined || this._streamName == ""))
  121.             {
  122.                this._autoSenseBW = this._streamName.indexOf(",") >= 0;
  123.                return _loc3_ || this.connectRTMP();
  124.             }
  125.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  126.          }
  127.          else
  128.          {
  129.             if(_loc2_.streamName.indexOf("?") < 0 && _loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  130.             {
  131.                _loc3_ = this.canReuseOldConnection(_loc2_);
  132.                this._isRTMP = false;
  133.                this._streamName = _loc2_.streamName;
  134.                return _loc3_ || this.connectHTTP();
  135.             }
  136.             if(_loc2_.streamName.indexOf("/fms/fpad") >= 0)
  137.             {
  138.                try
  139.                {
  140.                   return this.connectFPAD(_loc2_.streamName);
  141.                }
  142.                catch(err:Error)
  143.                {
  144.                }
  145.             }
  146.             this._smilMgr = new mx.video.SMILManager(this);
  147.             return this._smilMgr.connectXML(_loc2_.streamName);
  148.          }
  149.       }
  150.    }
  151.    function connectAgain()
  152.    {
  153.       var _loc2_ = this._appName.indexOf("/");
  154.       if(_loc2_ < 0)
  155.       {
  156.          _loc2_ = this._streamName.indexOf("/");
  157.          if(_loc2_ >= 0)
  158.          {
  159.             this._appName += "/";
  160.             this._appName += this._streamName.slice(0,_loc2_);
  161.             this._streamName = this._streamName.slice(_loc2_ + 1);
  162.          }
  163.          return false;
  164.       }
  165.       var _loc3_ = this._appName.slice(_loc2_ + 1);
  166.       _loc3_ += "/";
  167.       _loc3_ += this._streamName;
  168.       this._streamName = _loc3_;
  169.       this._appName = this._appName.slice(0,_loc2_);
  170.       this.close();
  171.       this._payload = 0;
  172.       this._connTypeCounter = 0;
  173.       this.cleanConns();
  174.       this.connectRTMP();
  175.       return true;
  176.    }
  177.    function reconnect()
  178.    {
  179.       if(!this._isRTMP)
  180.       {
  181.          throw new Error("Cannot call reconnect on an http connection");
  182.       }
  183.       else
  184.       {
  185.          this._nc.onStatus = function(info)
  186.          {
  187.             this.mc.reconnectOnStatus(this,info);
  188.          };
  189.          this._nc.onBWDone = function()
  190.          {
  191.             this.mc.onReconnected();
  192.          };
  193.          this._nc.connect(this._ncUri,false);
  194.       }
  195.    }
  196.    function onReconnected()
  197.    {
  198.       delete this._nc.onStatus;
  199.       delete this._nc.onBWDone;
  200.       this._ncConnected = true;
  201.       this._owner.ncReconnected();
  202.    }
  203.    function close()
  204.    {
  205.       if(this._nc)
  206.       {
  207.          this._nc.close();
  208.          this._ncConnected = false;
  209.       }
  210.    }
  211.    function helperDone(helper, success)
  212.    {
  213.       if(!success)
  214.       {
  215.          this._nc = undefined;
  216.          this._ncConnected = false;
  217.          this._owner.ncConnected();
  218.          this._smilMgr = undefined;
  219.          this._fpadMgr = undefined;
  220.          return undefined;
  221.       }
  222.       var _loc2_ = undefined;
  223.       var _loc4_ = undefined;
  224.       if(helper == this._fpadMgr)
  225.       {
  226.          _loc4_ = this._fpadMgr.rtmpURL;
  227.          this._fpadMgr = undefined;
  228.          _loc2_ = this.parseURL(_loc4_);
  229.          this._isRTMP = _loc2_.isRTMP;
  230.          this._protocol = _loc2_.protocol;
  231.          this._serverName = _loc2_.serverName;
  232.          this._portNumber = _loc2_.portNumber;
  233.          this._wrappedURL = _loc2_.wrappedURL;
  234.          this._appName = _loc2_.appName;
  235.          this._streamName = _loc2_.streamName;
  236.          var _loc5_ = this.fpadZone;
  237.          this.fpadZone = -1;
  238.          this.connectRTMP();
  239.          this.fpadZone = _loc5_;
  240.          return undefined;
  241.       }
  242.       if(helper != this._smilMgr)
  243.       {
  244.          return undefined;
  245.       }
  246.       this._streamWidth = this._smilMgr.width;
  247.       this._streamHeight = this._smilMgr.height;
  248.       _loc4_ = this._smilMgr.baseURLAttr[0];
  249.       if(_loc4_ != undefined && _loc4_ != "")
  250.       {
  251.          if(_loc4_.charAt(_loc4_.length - 1) != "/")
  252.          {
  253.             _loc4_ += "/";
  254.          }
  255.          _loc2_ = this.parseURL(_loc4_);
  256.          this._isRTMP = _loc2_.isRTMP;
  257.          this._streamName = _loc2_.streamName;
  258.          if(this._isRTMP)
  259.          {
  260.             this._protocol = _loc2_.protocol;
  261.             this._serverName = _loc2_.serverName;
  262.             this._portNumber = _loc2_.portNumber;
  263.             this._wrappedURL = _loc2_.wrappedURL;
  264.             this._appName = _loc2_.appName;
  265.             if(this._appName == undefined || this._appName == "")
  266.             {
  267.                this._smilMgr = undefined;
  268.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Base RTMP URL must include application name: " + _loc4_);
  269.             }
  270.             else if(this._smilMgr.baseURLAttr.length > 1)
  271.             {
  272.                _loc2_ = this.parseURL(this._smilMgr.baseURLAttr[1]);
  273.                if(_loc2_.serverName != undefined)
  274.                {
  275.                   this.fallbackServerName = _loc2_.serverName;
  276.                }
  277.             }
  278.          }
  279.       }
  280.       this._streams = this._smilMgr.videoTags;
  281.       this._smilMgr = undefined;
  282.       var _loc3_ = 0;
  283.       for(; _loc3_ < this._streams.length; this._streams[_loc3_].parseResults = _loc2_,_loc3_ = _loc3_ + 1)
  284.       {
  285.          _loc4_ = this._streams[_loc3_].src;
  286.          _loc2_ = this.parseURL(_loc4_);
  287.          if(this._isRTMP == undefined)
  288.          {
  289.             this._isRTMP = _loc2_.isRTMP;
  290.             if(this._isRTMP)
  291.             {
  292.                this._protocol = _loc2_.protocol;
  293.                if(this._streams.length > 1)
  294.                {
  295.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Cannot switch between multiple absolute RTMP URLs, must use meta tag base attribute.");
  296.                }
  297.                else
  298.                {
  299.                   this._serverName = _loc2_.serverName;
  300.                   this._portNumber = _loc2_.portNumber;
  301.                   this._wrappedURL = _loc2_.wrappedURL;
  302.                   this._appName = _loc2_.appName;
  303.                   if(this._appName == undefined || this._appName == "")
  304.                   {
  305.                      throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Base RTMP URL must include application name: " + _loc4_);
  306.                   }
  307.                }
  308.             }
  309.             else if(_loc2_.streamName.indexOf("/fms/fpad") >= 0 && this._streams.length > 1)
  310.             {
  311.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Cannot switch between multiple absolute fpad URLs, must use meta tag base attribute.");
  312.             }
  313.             continue;
  314.          }
  315.          if(!(this._streamName != undefined && this._streamName != "" && !_loc2_.isRelative && this._streams.length > 1))
  316.          {
  317.             continue;
  318.          }
  319.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"When using meta tag base attribute, cannot use absolute URLs for video or ref tag src attributes.");
  320.       }
  321.       this._autoSenseBW = this._streams.length > 1;
  322.       if(!this._autoSenseBW)
  323.       {
  324.          if(this._streamName != undefined)
  325.          {
  326.             this._streamName += this._streams[0].parseResults.streamName;
  327.          }
  328.          else
  329.          {
  330.             this._streamName = this._streams[0].parseResults.streamName;
  331.          }
  332.          this._streamLength = this._streams[0].dur;
  333.       }
  334.       if(this._isRTMP)
  335.       {
  336.          this.connectRTMP();
  337.       }
  338.       else if(this._streamName != undefined && this._streamName.indexOf("/fms/fpad") >= 0)
  339.       {
  340.          this.connectFPAD(this._streamName);
  341.       }
  342.       else
  343.       {
  344.          if(this._autoSenseBW)
  345.          {
  346.             this.bitrateMatch();
  347.          }
  348.          this.connectHTTP();
  349.          this._owner.ncConnected();
  350.       }
  351.    }
  352.    function bitrateMatch()
  353.    {
  354.       var _loc3_ = undefined;
  355.       var _loc4_ = this._bitrate;
  356.       if(isNaN(_loc4_))
  357.       {
  358.          _loc4_ = 0;
  359.       }
  360.       var _loc2_ = 0;
  361.       while(_loc2_ < this._streams.length)
  362.       {
  363.          if(isNaN(this._streams[_loc2_].bitrate) || _loc4_ >= this._streams[_loc2_].bitrate)
  364.          {
  365.             _loc3_ = _loc2_;
  366.             break;
  367.          }
  368.          _loc2_ = _loc2_ + 1;
  369.       }
  370.       if(isNaN(_loc3_))
  371.       {
  372.          throw new mx.video.VideoError(mx.video.VideoError.NO_BITRATE_MATCH);
  373.       }
  374.       else
  375.       {
  376.          if(this._streamName != undefined)
  377.          {
  378.             this._streamName += this._streams[_loc3_].src;
  379.          }
  380.          else
  381.          {
  382.             this._streamName = this._streams[_loc3_].src;
  383.          }
  384.          this._streamLength = this._streams[_loc3_].dur;
  385.       }
  386.    }
  387.    function parseURL(url)
  388.    {
  389.       var _loc2_ = new Object();
  390.       var _loc3_ = 0;
  391.       var _loc4_ = url.indexOf(":/",_loc3_);
  392.       if(_loc4_ >= 0)
  393.       {
  394.          _loc4_ += 2;
  395.          _loc2_.protocol = url.slice(_loc3_,_loc4_);
  396.          _loc2_.isRelative = false;
  397.       }
  398.       else
  399.       {
  400.          _loc2_.isRelative = true;
  401.       }
  402.       if(_loc2_.protocol != undefined && (_loc2_.protocol == "rtmp:/" || _loc2_.protocol == "rtmpt:/" || _loc2_.protocol == "rtmps:/"))
  403.       {
  404.          _loc2_.isRTMP = true;
  405.          _loc3_ = _loc4_;
  406.          if(url.charAt(_loc3_) == "/")
  407.          {
  408.             _loc3_ = _loc3_ + 1;
  409.             var _loc7_ = url.indexOf(":",_loc3_);
  410.             var _loc8_ = url.indexOf("/",_loc3_);
  411.             if(_loc8_ < 0)
  412.             {
  413.                if(_loc7_ < 0)
  414.                {
  415.                   _loc2_.serverName = url.slice(_loc3_);
  416.                }
  417.                else
  418.                {
  419.                   _loc4_ = _loc7_;
  420.                   _loc2_.portNumber = url.slice(_loc3_,_loc4_);
  421.                   _loc3_ = _loc4_ + 1;
  422.                   _loc2_.serverName = url.slice(_loc3_);
  423.                }
  424.                return _loc2_;
  425.             }
  426.             if(_loc7_ >= 0 && _loc7_ < _loc8_)
  427.             {
  428.                _loc4_ = _loc7_;
  429.                _loc2_.serverName = url.slice(_loc3_,_loc4_);
  430.                _loc3_ = _loc4_ + 1;
  431.                _loc4_ = _loc8_;
  432.                _loc2_.portNumber = url.slice(_loc3_,_loc4_);
  433.             }
  434.             else
  435.             {
  436.                _loc4_ = _loc8_;
  437.                _loc2_.serverName = url.slice(_loc3_,_loc4_);
  438.             }
  439.             _loc3_ = _loc4_ + 1;
  440.          }
  441.          if(url.charAt(_loc3_) == "?")
  442.          {
  443.             var _loc9_ = url.slice(_loc3_ + 1);
  444.             var _loc6_ = this.parseURL(_loc9_);
  445.             if(!(_loc6_.protocol == undefined || !_loc6_.isRTMP))
  446.             {
  447.                _loc2_.wrappedURL = "?";
  448.                _loc2_.wrappedURL += _loc6_.protocol;
  449.                if(_loc6_.serverName != undefined)
  450.                {
  451.                   _loc2_.wrappedURL += "/";
  452.                   _loc2_.wrappedURL += _loc6_.serverName;
  453.                }
  454.                if(_loc6_.wrappedURL != undefined)
  455.                {
  456.                   _loc2_.wrappedURL += "/?";
  457.                   _loc2_.wrappedURL += _loc6_.wrappedURL;
  458.                }
  459.                _loc2_.appName = _loc6_.appName;
  460.                _loc2_.streamName = _loc6_.streamName;
  461.                return _loc2_;
  462.             }
  463.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  464.          }
  465.          else
  466.          {
  467.             _loc4_ = url.indexOf("/",_loc3_);
  468.             if(_loc4_ < 0)
  469.             {
  470.                _loc2_.appName = url.slice(_loc3_);
  471.                return _loc2_;
  472.             }
  473.             _loc2_.appName = url.slice(_loc3_,_loc4_);
  474.             _loc3_ = _loc4_ + 1;
  475.             _loc4_ = url.indexOf("/",_loc3_);
  476.             if(_loc4_ < 0)
  477.             {
  478.                _loc2_.streamName = url.slice(_loc3_);
  479.                if(_loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  480.                {
  481.                   _loc2_.streamName = _loc2_.streamName.slice(0,-4);
  482.                }
  483.                return _loc2_;
  484.             }
  485.             _loc2_.appName += "/";
  486.             _loc2_.appName += url.slice(_loc3_,_loc4_);
  487.             _loc3_ = _loc4_ + 1;
  488.             _loc2_.streamName = url.slice(_loc3_);
  489.             if(_loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  490.             {
  491.                _loc2_.streamName = _loc2_.streamName.slice(0,-4);
  492.             }
  493.          }
  494.       }
  495.       else
  496.       {
  497.          _loc2_.isRTMP = false;
  498.          _loc2_.streamName = url;
  499.       }
  500.       return _loc2_;
  501.    }
  502.    function canReuseOldConnection(parseResults)
  503.    {
  504.       if(this._nc == undefined || this._nc == null || !this._ncConnected)
  505.       {
  506.          return false;
  507.       }
  508.       if(!parseResults.isRTMP)
  509.       {
  510.          if(!this._isRTMP)
  511.          {
  512.             return true;
  513.          }
  514.          this._owner.close();
  515.          this._nc = undefined;
  516.          this._ncConnected = false;
  517.          this.initNCInfo();
  518.          return false;
  519.       }
  520.       if(this._isRTMP)
  521.       {
  522.          if(parseResults.serverName == this._serverName && parseResults.appName == this._appName && parseResults.protocol == this._protocol && parseResults.portNumber == this._portNumber && parseResults.wrappedURL == this._wrappedURL)
  523.          {
  524.             return true;
  525.          }
  526.          this._owner.close();
  527.          this._nc = undefined;
  528.          this._ncConnected = false;
  529.       }
  530.       this.initNCInfo();
  531.       return false;
  532.    }
  533.    function connectHTTP()
  534.    {
  535.       this._nc = new NetConnection();
  536.       this._nc.connect(null);
  537.       this._ncConnected = true;
  538.       return true;
  539.    }
  540.    function connectRTMP()
  541.    {
  542.       clearInterval(this._timeoutIntervalId);
  543.       this._timeoutIntervalId = setInterval(this,"_onFCSConnectTimeOut",this._timeout);
  544.       this._tryNC = new Array();
  545.       var _loc2_ = 0;
  546.       while(_loc2_ < mx.video.NCManager.RTMP_CONN.length)
  547.       {
  548.          this._tryNC[_loc2_] = new NetConnection();
  549.          if(this.fpadZone != undefined && this.fpadZone != null)
  550.          {
  551.             this._tryNC[_loc2_].fpadZone = this.fpadZone;
  552.          }
  553.          this._tryNC[_loc2_].mc = this;
  554.          this._tryNC[_loc2_].pending = false;
  555.          this._tryNC[_loc2_].connIndex = _loc2_;
  556.          this._tryNC[_loc2_].onBWDone = function(p_bw)
  557.          {
  558.             this.mc.onConnected(this,p_bw);
  559.          };
  560.          this._tryNC[_loc2_].onBWCheck = function()
  561.          {
  562.             return ++this.mc._payload;
  563.          };
  564.          this._tryNC[_loc2_].onStatus = function(info)
  565.          {
  566.             this.mc.connectOnStatus(this,info);
  567.          };
  568.          _loc2_ = _loc2_ + 1;
  569.       }
  570.       this.nextConnect();
  571.       return false;
  572.    }
  573.    function connectFPAD(url)
  574.    {
  575.       var _loc7_ = undefined;
  576.       var _loc5_ = undefined;
  577.       var _loc6_ = undefined;
  578.       var _loc2_ = url.indexOf("?");
  579.       while(_loc2_ >= 0)
  580.       {
  581.          _loc2_ = _loc2_ + 1;
  582.          var _loc4_ = url.indexOf("&",_loc2_);
  583.          if(url.substr(_loc2_,4).toLowerCase() == "uri=")
  584.          {
  585.             _loc7_ = url.slice(0,_loc2_);
  586.             _loc2_ += 4;
  587.             if(_loc4_ >= 0)
  588.             {
  589.                _loc5_ = url.slice(_loc2_,_loc4_);
  590.                _loc6_ = url.slice(_loc4_);
  591.             }
  592.             else
  593.             {
  594.                _loc5_ = url.slice(_loc2_);
  595.                _loc6_ = "";
  596.             }
  597.             break;
  598.          }
  599.          _loc2_ = _loc4_;
  600.       }
  601.       if(_loc2_ < 0)
  602.       {
  603.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,"fpad url must include uri parameter: " + url);
  604.       }
  605.       else
  606.       {
  607.          var _loc8_ = this.parseURL(_loc5_);
  608.          if(!_loc8_.isRTMP)
  609.          {
  610.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,"fpad url uri parameter must be rtmp url: " + url);
  611.          }
  612.          else
  613.          {
  614.             this._fpadMgr = new mx.video.FPADManager(this);
  615.             return this._fpadMgr.connectXML(_loc7_,_loc5_,_loc6_,_loc8_);
  616.          }
  617.       }
  618.    }
  619.    function nextConnect()
  620.    {
  621.       clearInterval(this._tryNCIntervalId);
  622.       this._tryNCIntervalId = 0;
  623.       var _loc4_ = undefined;
  624.       var _loc3_ = undefined;
  625.       if(this._connTypeCounter == 0)
  626.       {
  627.          _loc4_ = this._protocol;
  628.          if(this._portNumber != undefined)
  629.          {
  630.             _loc3_ = this._portNumber;
  631.          }
  632.          else
  633.          {
  634.             var _loc2_ = 0;
  635.             while(_loc2_ < mx.video.NCManager.RTMP_CONN.length)
  636.             {
  637.                if(_loc4_ == mx.video.NCManager.RTMP_CONN[_loc2_].protocol)
  638.                {
  639.                   _loc3_ = mx.video.NCManager.RTMP_CONN[_loc2_].port;
  640.                   break;
  641.                }
  642.                _loc2_ = _loc2_ + 1;
  643.             }
  644.          }
  645.       }
  646.       else
  647.       {
  648.          _loc4_ = mx.video.NCManager.RTMP_CONN[this._connTypeCounter].protocol;
  649.          _loc3_ = mx.video.NCManager.RTMP_CONN[this._connTypeCounter].port;
  650.       }
  651.       var _loc5_ = _loc4_ + (this._serverName != undefined ? "/" + this._serverName + ":" + _loc3_ + "/" : "") + (this._wrappedURL != undefined ? this._wrappedURL + "/" : "") + this._appName;
  652.       this._tryNC[this._connTypeCounter].pending = true;
  653.       this._tryNC[this._connTypeCounter].connect(_loc5_,this._autoSenseBW);
  654.       if(this._connTypeCounter < mx.video.NCManager.RTMP_CONN.length - 1)
  655.       {
  656.          this._connTypeCounter = this._connTypeCounter + 1;
  657.          this._tryNCIntervalId = setInterval(this,"nextConnect",1500);
  658.       }
  659.    }
  660.    function cleanConns()
  661.    {
  662.       clearInterval(this._tryNCIntervalId);
  663.       this._tryNCIntervalId = 0;
  664.       if(this._tryNC != undefined)
  665.       {
  666.          var _loc2_ = 0;
  667.          while(_loc2_ < this._tryNC.length)
  668.          {
  669.             if(this._tryNC[_loc2_] != undefined)
  670.             {
  671.                delete this._tryNC[_loc2_].onStatus;
  672.                if(this._tryNC[_loc2_].pending)
  673.                {
  674.                   this._tryNC[_loc2_].onStatus = function(info)
  675.                   {
  676.                      this.mc.disconnectOnStatus(this,info);
  677.                   };
  678.                }
  679.                else
  680.                {
  681.                   delete this._tryNC[_loc2_].onStatus;
  682.                   this._tryNC[_loc2_].close();
  683.                }
  684.             }
  685.             delete this._tryNC[_loc2_];
  686.             _loc2_ = _loc2_ + 1;
  687.          }
  688.          delete this._tryNC;
  689.       }
  690.    }
  691.    function tryFallBack()
  692.    {
  693.       if(this._serverName == this.fallbackServerName || this.fallbackServerName == undefined || this.fallbackServerName == null)
  694.       {
  695.          delete this._nc;
  696.          this._nc = undefined;
  697.          this._ncConnected = false;
  698.          this._owner.ncConnected();
  699.       }
  700.       else
  701.       {
  702.          this._connTypeCounter = 0;
  703.          this.cleanConns();
  704.          this._serverName = this.fallbackServerName;
  705.          this.connectRTMP();
  706.       }
  707.    }
  708.    function onConnected(p_nc, p_bw)
  709.    {
  710.       clearInterval(this._timeoutIntervalId);
  711.       this._timeoutIntervalId = 0;
  712.       delete p_nc.onBWDone;
  713.       delete p_nc.onBWCheck;
  714.       delete p_nc.onStatus;
  715.       this._nc = p_nc;
  716.       this._ncUri = this._nc.uri;
  717.       this._ncConnected = true;
  718.       if(this._autoSenseBW)
  719.       {
  720.          this._bitrate = p_bw * 1024;
  721.          if(this._streams != undefined)
  722.          {
  723.             this.bitrateMatch();
  724.          }
  725.          else
  726.          {
  727.             var _loc3_ = this._streamName.split(",");
  728.             var _loc2_ = 0;
  729.             while(_loc2_ < _loc3_.length)
  730.             {
  731.                var _loc4_ = mx.video.NCManager.stripFrontAndBackWhiteSpace(_loc3_[_loc2_]);
  732.                if(_loc2_ + 1 >= _loc3_.length)
  733.                {
  734.                   this._streamName = _loc4_;
  735.                   break;
  736.                }
  737.                if(p_bw <= Number(_loc3_[_loc2_ + 1]))
  738.                {
  739.                   this._streamName = _loc4_;
  740.                   break;
  741.                }
  742.                _loc2_ += 2;
  743.             }
  744.             if(this._streamName.slice(-4).toLowerCase() == ".flv")
  745.             {
  746.                this._streamName = this._streamName.slice(0,-4);
  747.             }
  748.          }
  749.       }
  750.       if(!this._owner.__get__isLive() && this._streamLength == undefined)
  751.       {
  752.          var _loc6_ = new Object();
  753.          _loc6_.mc = this;
  754.          _loc6_.onResult = function(length)
  755.          {
  756.             this.mc.getStreamLengthResult(length);
  757.          };
  758.          this._nc.call("getStreamLength",_loc6_,this._streamName);
  759.       }
  760.       else
  761.       {
  762.          this._owner.ncConnected();
  763.       }
  764.    }
  765.    function connectOnStatus(target, info)
  766.    {
  767.       target.pending = false;
  768.       if(info.code == "NetConnection.Connect.Success")
  769.       {
  770.          this._nc = this._tryNC[target.connIndex];
  771.          this._tryNC[target.connIndex] = undefined;
  772.          this.cleanConns();
  773.       }
  774.       else if((info.code == "NetConnection.Connect.Failed" || info.code == "NetConnection.Connect.Rejected") && target.connIndex == mx.video.NCManager.RTMP_CONN.length - 1)
  775.       {
  776.          if(!this.connectAgain())
  777.          {
  778.             this.tryFallBack();
  779.          }
  780.       }
  781.    }
  782.    function reconnectOnStatus(target, info)
  783.    {
  784.       if(info.code == "NetConnection.Connect.Failed" || info.code == "NetConnection.Connect.Rejected")
  785.       {
  786.          delete this._nc;
  787.          this._nc = undefined;
  788.          this._ncConnected = false;
  789.          this._owner.ncReconnected();
  790.       }
  791.    }
  792.    function disconnectOnStatus(target, info)
  793.    {
  794.       if(info.code == "NetConnection.Connect.Success")
  795.       {
  796.          delete target.onStatus;
  797.          target.close();
  798.       }
  799.    }
  800.    function getStreamLengthResult(length)
  801.    {
  802.       if(length > 0)
  803.       {
  804.          this._streamLength = length;
  805.       }
  806.       this._owner.ncConnected();
  807.    }
  808.    function _onFCSConnectTimeOut()
  809.    {
  810.       this.cleanConns();
  811.       this._nc = undefined;
  812.       this._ncConnected = false;
  813.       if(!this.connectAgain())
  814.       {
  815.          this._owner.ncConnected();
  816.       }
  817.    }
  818.    static function stripFrontAndBackWhiteSpace(p_str)
  819.    {
  820.       var _loc1_ = undefined;
  821.       var _loc2_ = p_str.length;
  822.       var _loc4_ = 0;
  823.       var _loc5_ = _loc2_;
  824.       _loc1_ = 0;
  825.       for(; _loc1_ < _loc2_; _loc1_ = _loc1_ + 1)
  826.       {
  827.          switch(p_str.charCodeAt(_loc1_))
  828.          {
  829.             case 9:
  830.             case 10:
  831.             case 13:
  832.             case 32:
  833.                continue;
  834.             default:
  835.                _loc4_ = _loc1_;
  836.          }
  837.       }
  838.       _loc1_ = _loc2_;
  839.       for(; _loc1_ >= 0; _loc1_ = _loc1_ - 1)
  840.       {
  841.          switch(p_str.charCodeAt(_loc1_))
  842.          {
  843.             case 9:
  844.             case 10:
  845.             case 13:
  846.             case 32:
  847.                continue;
  848.             default:
  849.                _loc5_ = _loc1_ + 1;
  850.          }
  851.       }
  852.       if(_loc5_ <= _loc4_)
  853.       {
  854.          return "";
  855.       }
  856.       return p_str.slice(_loc4_,_loc5_);
  857.    }
  858. }
  859.